#!/bin/bash

ip=`ifconfig |grep -A 1 -w "^eth0"  |grep inet |awk '{print$2}'`

last_commit_info=$(git show -s --format="%h %s %ad" --date=iso HEAD)

current_branch=$(git branch --show-current)

# 执行 git pull 操作
if git pull; then
    content="ip：${ip}||项目路径:$(pwd)||分支:${current_branch}||最后提交信息:${last_commit_info}"
    json_data=$(printf '{"msgtype": "text", "text": { "content": "%s ,Git pull 成功！"}}' "$content" )
    echo $json_data
    curl -X POST 'https://oapi.dingtalk.com/robot/send?access_token=3adade349c1892d8d7ce71db4b511523b2e51c5b35d47d12ab1fac28ed3ff6f0' \
    -H 'Content-Type: application/json' \
    -d  "$json_data"

else

    content="ip：${ip}||项目路径:$(pwd)||分支:${current_branch}"
    json_data=$(printf '{"msgtype": "text", "text": { "content": "%s ,Git pull 失败啦！快去服务器上检查吧！！！！"}}' "$content" )
    echo  $json_data
    curl -X POST 'https://oapi.dingtalk.com/robot/send?access_token=3adade349c1892d8d7ce71db4b511523b2e51c5b35d47d12ab1fac28ed3ff6f0' \
    -H 'Content-Type: application/json' \
    -d  "$json_data"

fi